//
//  DetailtreatMents.m
//  EcmDoctor
//
//  Created by Mac on 16/2/25.
//  Copyright © 2016年 张进. All rights reserved.
//

#import "DetailtreatMents.h"
#import "NetWorkUtil.h"
#import <SSKeychain/SSKeychain.h>
#import "AppUtils.h"
@implementation DetailtreatMents

+(void)getCureSchemeInfoById:(NSString *)curescheme_info_id And:(NSString *)cure_type success:(void (^)(NSArray *))success failure:(void (^)(NSError *))failure
{
    NetWorkBaseRequest *req = [[NetWorkBaseRequest alloc] init];
    //请求参数
    
    req.moduleName = @"UserRS";
    req.methodName = @"getCureSchemeInfoById";
    [req setValue:curescheme_info_id forKey:@"curescheme_info_id"];
    [req setValue:cure_type forKey:@"cure_type"];
    
    [NetWorkUtil requestWithPOST:req success:^(NetWorkBaseResponse *responseObject) {
        NSError *error = nil;
      
        if (responseObject.code.integerValue == 1) {
            if (!responseObject.data) {
                success(nil);
                return;
            }
            NSData *data = [responseObject.data dataUsingEncoding:NSUTF8StringEncoding];
            NSArray *userAttrs = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
          
            if (error) {
                failure(error);
                return;
            }
            NSMutableArray *ary1=[NSMutableArray array];
            for(int i=0;i<userAttrs.count;i++)
            {
                DetailtreatMents*detailtreatMents=[[DetailtreatMents alloc]initWithDictionary:userAttrs[i]];
                detailtreatMents.cureAry=[NSMutableArray array];
                NSArray *ary=userAttrs[i][@"childInfos"];
                for(int l=0;l<ary.count;l++)
                {
                    CureSchemeChildInfo *cureSchemeChildInfo=[[CureSchemeChildInfo alloc]initWithDictionary:ary[l]];
                
                    [detailtreatMents.cureAry addObject:cureSchemeChildInfo];
                }
                
                [ary1 addObject:detailtreatMents];
            }
            
            
            success(ary1);
            
        }
        else{
            error = [NSError errorWithDomain:responseObject.msg code:responseObject.code.integerValue userInfo:nil];
            failure(error);
        }
        
    } failure:^(NSError *error) {
        failure(error);
        
    } cache:NO];
    
    

}
@end
